      SUBROUTINE QUIKVIS5A2C(ITARG,IDTARG,TARGNAMES,KTARGTYP,TARGPARM,
     *     IERR)
      IMPLICIT REAL*8 (A-H,O-Z)
C
C THIS ROUTINE IS PART OF THE QUIKVIS PROGRAM.  IT GIVES THE DETAIL
C OUTPUT INFO FOR TARGET AVAILABILITY FOR THE ITARG'TH TARGET(ITARG
C IS SPECIFIED IN THE CALLING SEQUENCE).
C
C
C VARIABLE      DIM       TYPE I/O DESCRIPTION
C --------      ---       ---- --- -----------
C
C ITARG          1         I*4  I  INDEX OF THE TARGET FOR WHICH OUTPUT
C                                  IS TO BE GENERATED.
C
C IDTARG      MAXTARGS     I*4  I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C TARGNAMES   MAXTARGS    CH*16 I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C KTARGTYP    MAXTARGS     I*4  I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C TARGPARM NPARMS,MAXTARGS R*8  I  DESCRIBED IN QUIKVIS(=MAIN) PROLOGUE.
C
C IERR           1         I*4  O  ERROR RETURN FLAG
C                                  =0, NO ERROR
C                                  =OTHERWISE, ERROR.
C
C***********************************************************************
C
C BY C PETRUZZO/GFSC/742.   2/86.
C       MODIFIED.... 9/86. CJP. EXTENSIVE MODS REFLECT THE ADDITION OF
C                               AN OPTION TO GENERATE A DETAILED DATA
C                               FILE, A SWITCH FROM WORKING IN TRUE
C                               ANOMALY TO MEAN ANOMALY, AND SOME FORMAT
C                               CHANGES IN DETAIL DATA PRINTED INFO.
C                               COMMENTS HAVE BEEN EXPANDED FOR CLARITY.
C       MODIFIED.... 3/87. CJP. MODERATE AMOUNT OF MODS TO ADD MORE
C                               LEVELS OF DETAIL TO THE DETAIL DATA
C                               FILE.  SOME RESTRUCTURING OF OTHER
C                               LOGIC FOR CLARITY.
C
C***********************************************************************
C
      INCLUDE 'QUIKVIS.INC'
C
      CHARACTER*16 TARGNAMES(MAXTARGS)
      INTEGER*4 IDTARG(MAXTARGS)
      REAL*8 TARGPARM(NPARMS,MAXTARGS)
      INTEGER*4 KTARGTYP(MAXTARGS)
C
      REAL*8 VISTIMES(MAXNODES),EVENTMA(MAXNODES)
      INTEGER LU(2)
      CHARACTER*60 SHADTEXT
      REAL*8 SUNPOS(3),TARGVEC(3)
      REAL*8 REQMTMA(2,MAXREQMT,MAXNODES),RELMA(2,MAXREQMT),
     *       OVERLAP(2,MAXREQMT)
      REAL*8 REQMA(2,MAXNODES)
      INTEGER NOLAPREQ(MAXREQMT)
      CHARACTER*16 CH16NAME
      CHARACTER*18 DATETIME
      CHARACTER*20 CH20
      CHARACTER*4 CH4
      LOGICAL DODETL(4),SOMETRUE,ALWAYS,NEVER
      LOGICAL*1 SEGCIRC(MAXSEGCIRC)
      PARAMETER MAXOLAPREQ = 10  ! VERY CONSERVATIVE;  =10 IN 5A2C3 ALSO
      REAL*8 OVLAPREQ(2,MAXOLAPREQ,MAXREQMT)
C
      CHARACTER*121 BAR,BARGUAR
      CHARACTER*9 BARTITL(MAXREQMT)/
     *    'HORIZON  ', 'ORB-NITE ',  'VEL-AVOID', 'ZEN SEP  '/
C
C
      IBUG = 0
      LUBUG = 19
C
C
C ****************
C *  INITIALIZE  *
C ****************
C
      IERR = 0
C
C
C SET UNIT NUMBERS TO WHICH PRINTED OUTPUT IS DIRECTED
C
      LU(1) = LUPRINT
      IF(.NOT.TOPRINT) LU(1) = 0
      LU(2) = LUPROMPT
      IF(.NOT.TOPROMPT) LU(2) = 0
      IF(LUPRINT.EQ.LUPROMPT) LU(2) = 0  ! ELIMINATES DUPLICATE WRITES
C
C
C SET THE NUMBER OF ORBIT RAAN'S INVOLVED
C
      IF(NODEOPT.EQ.1) THEN
        NUMNODES = NUMRAAN
      ELSE IF(NODEOPT.EQ.2) THEN
        NUMNODES = NUMSOLT
      ELSE
        STOP ' QUIKVIS5A2C. CODING ERROR. STOP 1. SEE CODE.'
        END IF
C
C
C SET TEXT STRING TELLING ABOUT ORBIT NIGHT REQMT
C
      IF(DOREQMT(2)) THEN
        SHADTEXT = 'TARGET AVAILABILITY REQUIRES ORBIT NIGHT'
      ELSE
        SHADTEXT = 'TARGET AVAILABILITY IGNORES ORBIT NIGHT.'
        END IF
C
C COUNT THE NUMBER OF CHARACTERS BEFORE THE FIRST TRAILING BLANK IN THE
C TEXT STRING DESCRIBING THE ORBIT EVENT TO WHICH SOME OUTPUT IS
C REFERENCED.
C
        CALL CHBLANK(ORBEVENT(KRELTIME),KDUM,NCHREL)
C
C ERROR CHECK.  DOBARS2 =.TRUE. SHOWS THE TARGET AVAILABILITY AS TIME
C SINCE THE EVENT IDENTIFIED BY THE GLOBAL PARAMETER KRELTIME.  THE
C MAXIMUM ORBITAL PERIOD THAT CAN BE SHOWN IS 120 MINUTES.  IF GREATER
C THAN 120, TURN OFF THE OPTION RATHER THAN SHOW INCORRECT OUTPUT.
C
      IF(DOBARS2 .AND. PERIOD.GT.7200.D0) THEN
        DOBARS2 = .FALSE.
        WRITE(LUERR,7201)
        END IF
C
C
C SET THE DODETL FLAGS TO INDICATE WHICH OUTPUT OPTIONS ARE TO BE DONE
C IN THE 'DO 6000' LOOP BELOW.
C
      DODETL(1) = DODETTABLE
      DODETL(2) = DOBARS1
      DODETL(3) = DOBARS2
      DODETL(4) = LEVDETFILE.NE.0
C
C
C SET MISC PARAMETER VALUES
C
      AU = CONST(60)
C
C
C ************
C *  OUTPUT  *       DO IT FOR EACH DATE AND TIME
C ************
C
C
      DO ITIME=1,NUMTIMES
C
C      READ DATA FOR THIS TIME FROM THE SCRATCH DATA FILE.
        CALL QV5READ(ITIME,
     *        T50,KDUM,ID,CH16NAME,
     *        FIRSTNODE,DELNODE,FIRSTMST,DELMST,NUMNODES,
     *        .TRUE.,EVENTMA, .TRUE.,VISTIMES, .TRUE.,REQMTMA)
C
C      GET SUN POSITION FOR OUTPUT
        CALL SOLM50(T50,SUNPOS,0)
        CALL XYZSPH(-1,RASUN,DECSUN,SUNDIST,SUNPOS,1.D0)
C
C      GET TARGET POSITION FOR OUTPUT(IF MOVING).
        IF(KTARGTYP(ITARG).EQ.1) THEN
          CALL TGLOC(1,1,TARGNAMES(ITARG),1,DUM,1,1,TARGVEC,
     *       1,T50, 0,DUM, 0,DUM, 0,DUM, 0,DUM, LUERR,IERR)
          IF(IERR.NE.0) GO TO 9999
          CALL XYZSPH(-1,RATARG,DECTARG,TARGDIST,TARGVEC,1.D0)
        ELSE
          RATARG =  TARGPARM(1,ITARG)
          DECTARG = TARGPARM(2,ITARG)
          END IF
C
C**** DO THE DETAIL OUTPUT FOR THIS TARGET AND TIME; DO ONE DETAIL
C     OPTION AT A TIME.
C
        DO 6000 IDETAIL=1,4
        IF(.NOT.DODETL(IDETAIL)) GO TO 6000
C
C        >>>>  PUT HEADER LINES ON THE PRINT UNIT(S)  <<<<
C
C      ON PRINT UNIT(S), WRITE HEADER INFO FOR THIS TARG: ID, NAME,
C      OBSERVATION REQMTS
C
        IF(IDETAIL.EQ.1 .OR. IDETAIL.EQ.2 .OR. IDETAIL.EQ.3) THEN
C
C        WRITE TARGET AND OBS REQMT INFO
          DO ILU=1,2
            IF(LU(ILU).GT.0) WRITE(LU(ILU),2010) DATETIME(0),
     *          IDTARG(ITARG),TARGNAMES(ITARG),
     *          SHADTEXT, EAVOID*DEGRAD, VAVOID*DEGRAD, ZMAXSEP*DEGRAD
            END DO
C
C        WRITE SUN AND TARGET(IF MOVING) POSITION
          DO ILU=1,2
            IF(LU(ILU).GT.0) THEN
              CALL PAKT50CH(T50,CH20)
              CH20(12:12) = ':'
              CH20(15:15) = ':'
              WRITE(LU(ILU),2110) CH20(1:17),(T50-TSTART)/86400.D0,
     *          RASUN*DEGRAD,DECSUN*DEGRAD,SUNDIST/AU
              IF(KTARGTYP(ITARG).EQ.1) WRITE(LU(ILU),2111)
     *          RATARG*DEGRAD,DECTARG*DEGRAD,TARGDIST/AU
              END IF
            END DO
C
          END IF  ! ENDS THE 'IF(IDETAIL=1,2,3)'
C
C
C      BRANCH TO CODE UNIQUE TO THE DETAIL OPTION BEING PROCESSED
        GO TO (6001,6002,6003,6004),IDETAIL
C
 6001   CONTINUE
C
C      *** TABLE FORMAT ***
C
C      FOR EACH NODE AND EACH REQUIREMENT, GIVE THE RELATIVE MEAN
C      ANOMALY VALUES WHERE THE REQUIREMENT IS SATISFIED.
C
        DO INODE=1,NUMNODES
          RAAN = EQVANG((FIRSTNODE+(INODE-1)*DELNODE))
C        CONVERT SCRATCH FILE MEAN ANOMALIES TO RELATIVE VALUES.
          CALL QUIKVIS5V(REQMTMA(1,1,INODE),EVENTMA(INODE),RELMA)
C        WRITE THE INFO
          DO ILU=1,2
            IF(LU(ILU).GT.0) THEN
              IF(INODE.EQ.1) WRITE(LU(ILU),2113)      ! COLUMN HEADERS
     *                ORBEVENT(KRELTIME)
              WRITE(LU(ILU),2114)
     *          RAAN*DEGRAD,
     *          DMOD((FIRSTMST+(INODE-1)*DELMST)/3600.D0,24.D0),
     *          VISTIMES(INODE)/60.D0, EVENTMA(INODE)*DEGRAD,
     *          ((RELMA(I,J)*DEGRAD,I=1,2),J=1,MAXREQMT)
              END IF    ! END 'IF(LU(ILU).GT.0)' BLOCK
            END DO    ! END ILU LOOP
          END DO    ! END INODE LOOP FOR THIS DETAIL OUTPUT OPTION
C
        GO TO 6000
C
C
 6002   CONTINUE
C
C      *** BAR FORMAT ***  (SHOWS INDIVIDUAL REQMTS FOR EACH NODE)
C
C      OUTPUT A GROUP OF BARS FOR EACH RAAN PROCESSED.  FOR EACH NODE,
C      AND FOR EACH REQMT, WRITE A BAR INDICATING WHERE THE REQMT
C      IS SATISFIED
C
        DO INODE=1,NUMNODES
          RAAN = EQVANG((FIRSTNODE+(INODE-1)*DELNODE))
C        WRITE HEADER LINE FOR THIS RAAN
          DO ILU=1,2
            IF(LU(ILU).GT.0) THEN
              IF(INODE.EQ.1) WRITE(LU(ILU),3099) ORBEVENT(KRELTIME)
              WRITE(LU(ILU),3100) RAAN*DEGRAD,
     *          DMOD( (FIRSTMST+(INODE-1)*DELMST)/3600.D0, 24.D0),
     *          VISTIMES(INODE)/60.D0
              END IF
            END DO
C        CONVERT SCRATCH FILE MEAN ANOMALIES TO RELATIVE VALUES.
          CALL QUIKVIS5V(REQMTMA(1,1,INODE),EVENTMA(INODE),RELMA)
          DO IREQ=1,MAXREQMT
            IF(DOREQMT(IREQ)) THEN
C            LOAD THE BAR FOR THIS REQUIREMENT
              CALL QUIKVIS5A2C1(IREQ,RELMA(1,IREQ),BAR)
C            OUTPUT THE BAR FOR THIS REQUIREMENT
              DO ILU=1,2
                IF(LU(ILU).GT.0) WRITE(LU(ILU),3101) BARTITL(IREQ),BAR
                END DO
              END IF
            END DO      ! END THE 'DO IREQ=' LOOP
C        WRITE FINAL LINES FOR THIS RAAN
          DO ILU=1,2
            IF(LU(ILU).GT.0) WRITE(LU(ILU),3102) (I,I=15,360,15)
            END DO
          END DO    ! END INODE LOOP FOR THIS DETAIL OUTPUT OPTION
C
        GO TO 6000
C
C
 6003   CONTINUE
C
C      *** BAR FORMAT ***
C
C      FOR EACH NODE, SHOW THE TIMES, RELATIVE TO THE ORBITAL EVENT,
C      WHERE ALL REQUIREMENTS ARE SATISFIED SIMULTANEOUSLY.  THEN
C      GIVE ONE MORE BAR SHOWING WHERE ALL PREVIOUS BARS OVERLAP.
C
C      WRITE HEADER LINES
C
        CH4 = 'ERRR'
        IF(NODEOPT.EQ.1) CH4 = 'RAAN'
        IF(NODEOPT.EQ.2) CH4 = ' MST'
        DO ILU=1,2
          IF(LU(ILU).GT.0) THEN
            WRITE(LU(ILU),4103) ORBEVENT(KRELTIME)(1:NCHREL)
            WRITE(LU(ILU),4105)
     *          FIRSTNODE*DEGRAD,FIRSTMST/3600.D0
            WRITE(LU(ILU),4102)  (I,I=10,JIDNNT(PERIOD/60.D0),10)
            WRITE(LU(ILU),4101) CH4,
     *            '+',('    +    +',I=10,JIDNNT(PERIOD/60.D0),10)
            END IF
          END DO
C
C      OUTPUT ONE BAR FOR EACH RAAN PROCESSED.
C
        DO INODE=1,NUMNODES
C        LOAD BAR CHARACTER STRING
          CALL QUIKVIS5A2C2(REQMTMA(1,1,INODE),EVENTMA(INODE),BAR)
C        WRITE THE LINE.
          IF(NODEOPT.EQ.1) THEN
            NDECIML = 1   ! NUMBER OF DIGITS AFTER DECIMAL, FORMAT 4100
            TEMP = EQVANG((FIRSTNODE+(INODE-1)*DELNODE)) * DEGRAD
          ELSE
            NDECIML = 2
            TEMP = DMOD((FIRSTMST+(INODE-1)*DELMST)/3600.D0,24.D0)
            END IF
          DO ILU=1,2
            IF(LU(ILU).GT.0) WRITE(LU(ILU),4100) TEMP,BAR
            END DO
C        BARGUAR IS A ROUGH GUIDE TO SHOWING TIMES, REL TO MERIDIAN
C        CROSSING, WHEN TARGET IS AVAIL FOR ALL NODES PROCESSED. THAT
C        IS, WHERE INDIVIDUAL BARS FOR ALL NODES OVERLAP.  THIS IS NOT
C        PRECISE, BUT IT IS USEFUL.  NOW UPDATE BARGUAR TO ACCOUNT FOR
C        THE CURRENT BAR CONTENTS.
          IF(INODE.EQ.1) THEN
            BARGUAR = BAR
          ELSE
            DO I=1,121
              IF(BAR(I:I).EQ.' ' .OR. BAR(I:I).EQ.'X')
     *                BARGUAR(I:I) = ' '
              END DO
            END IF
          END DO   ! END INODE LOOP
C
C      WRITE TRAILER LINES
C
        DO ILU=1,2
          IF(LU(ILU).GT.0) THEN
            WRITE(LU(ILU),4101) ' ',
     *             '+',('    +    +',I=10,JIDNNT(PERIOD/60.D0),10)
            WRITE(LU(ILU),4102)   (I,I=10,JIDNNT(PERIOD/60.D0),10)
            END IF
          END DO
C
C      SHOW THE BAR OF GUARANTEED AVAILABILITY
C
        DO ILU=1,2
          IF(LU(ILU).GT.0) THEN
            WRITE(LU(ILU),4104) BARGUAR
            WRITE(LU(ILU),4101) ' ',
     *            '+',('----+----+',I=10,JIDNNT(PERIOD/60.D0),10)
            WRITE(LU(ILU),4102)  (I,I=10,JIDNNT(PERIOD/60.D0),10)
            END IF
          END DO
C
        GO TO 6000
C
C
 6004   CONTINUE
C
C
C      *** DATA FILE, LUDETAIL, WITH DETAIL INFO PRESENT ***
C            (FILE HEADERS WERE WRITTEN BY QUIKVIS5A3)
C
C      FOR EACH RAAN PROCESSED WITH THIS TIME AND TARGET COMBINTAION,
C      WRITE A DATA RECORD GIVING THE MEAN ANOMALY RANGE, RELATIVE TO
C      A USER-SPECIFIED EVENT, WHERE ALL REQUIREMENTS ARE SATISFIED.
C      OTHER INFO IS INCLUDED IN THE RECORD ALSO.
C
C      FIRST, SCAN THE NODES TO GENERATE AVAIALBILITY INFO THAT ACCOUNTS
C      FOR ALL NODES AT THE CURRENT TIME AND ALL OBSVN REQUIREMENTS.  IF
C      MAX OR ALMOST MAX DETAIL IS WANTED,  WRITE INFO FOR INDIVIDUAL
C      NODES AS THEY ARE ENCOUNTERED.
C
        DO INODE=1,NUMNODES
          RAAN = EQVANG(FIRSTNODE+(INODE-1)*DELNODE)
C
C        FIND THE COMMON SEGMENT(S) WHERE THE MEAN ANOMALY RANGES FOR
C        INDIVIDUAL REQUIREMENTS ARE SATISFIED FOR THIS TARGET, TIME,
C        AND RAAN COMBINATION.  THIS DEFINES THE AVAILABILITY FOR THE
C        CURRENT TIME AND RAAN.
C
          CALL MTXSETR8(OVERLAP,0.D0,2,MAXREQMT)
          CALL ANGLAP(REQMTMA(1,1,INODE),MAXREQMT,OVERLAP,
     *              MAXREQMT,NOVERLAP,LUERR,IERR)
          NLAP = MAX(1,NOVERLAP)
          IF(IERR.NE.0) THEN
C          ERROR SHOULD NEVER OCCUR.  STOP TO FORCE A LOOK.
            STOP 'QUIKVIS5A2C. ERROR STOP 2. SEE CODE.'
            END IF
C
C        CONVERT OVERLAP ARRAY FROM MEAN ANOMALY RELATIVE TO PERIGEE
C        TO MEAN ANOMALY RELATIVE TO THE ORBIT EVENT DEFINED BY THE
C        GLOBAL PARAMETER KRELTIME.
C
          IF(NOVERLAP.GT.0.D0) THEN
            DO I=1,NOVERLAP
              ALWAYS = NOVERLAP.EQ.1 .AND.
     *             OVERLAP(1,1).EQ.0.D0 .AND. OVERLAP(2,1).EQ.TWOPI
              IF(.NOT.ALWAYS) THEN
                OVERLAP(1,I) = EQVANG(OVERLAP(1,I)-EVENTMA(INODE))
                OVERLAP(2,I) = EQVANG(OVERLAP(2,I)-EVENTMA(INODE))
                IF(OVERLAP(2,I).LT.OVERLAP(1,I))
     *                OVERLAP(1,I) = OVERLAP(1,I) - TWOPI
                END IF
              END DO
            END IF
C
C        UPDATE THE COMPOSITE(IE, FOR ALL RAAN'S) AVAILABILITY ARRAY.
C        A CIRCLE HAS BEEN DIVIDED INTO MAXSEGCIRC SEGMENTS.  EACH
C        SEGMENT HAS AN ASSOCIATED T/F FLAG IN THE LOGICAL ARRAY
C        SEGCIRC.  THE ISEG'TH VALUE IN SEGCIRC IS TRUE WHEN THE TARGET
C        IS AVAILABLE AT THE RELATIVE MEAN ANOMALY(RELATIVE TO THE
C        REFERENCE ORBIT EVENT DEFINED BY KRELTIME).  SEGMENT NUMBER 1
C        IS THE SEGMENT THAT BEGINS WHEN THE EVENT OCCURS.
C
          IF(INODE.EQ.1 .OR. SOMETRUE) CALL QUIKVIS5W(INODE,SEGCIRC,
     *                    NOVERLAP,OVERLAP,SOMETRUE)
C
          IF(IBUG.NE.0) THEN
            KSKIP = MAXSEGCIRC/90
            WRITE(LUBUG,5655) ITARG,PAKTIM50(T50),INODE,RAAN*DEGRAD,
     *         EVENTMA(INODE)*DEGRAD,
     *         NOVERLAP,
     *         (OVERLAP(1,J)*DEGRAD,OVERLAP(2,J)*DEGRAD,J=1,NLAP),
     *         (SEGCIRC((I-1)*KSKIP+1),I=1,90),
     *         (MOD(I-1,10),I=1,10)
 5655       FORMAT(' QUIKVIS5A2C DEBUG 5655.  ITARG=',I3,
     *         '  TIME=',F14.6,'  INODE=',I3,'  RAAN=',F8.2,
     *             '   EVENTMA=',F8.2/,
     *         '  NOVERLAP=',I2,'   OVERLAP='/,
     *          <NLAP>(T12,2(F9.3,', ')/),
     *         '  SEGCIRC=',90L1/,
     *         '          ',10(I1,9X))
            END IF
C
C        IF LEVDETFILE CALLS FOR IT, WRITE DATA FOR INDIVIDUAL RAAN'S
C        AS THEY ARE ENCOUNTERED.  COMPOSITE INFO FOR ALL RAAN'S WILL BE
C        WRITTEN IN QUIKVIS5A2C3 AFTER ALL RAAN'S HAVE BEEN PROCESSED.
C
          IF(LEVDETFILE.EQ.3 .OR. LEVDETFILE.EQ.4) THEN
C
C          DETERMINE THE RAAN'S MEAN SOLAR TIME
            XMST = DMOD((FIRSTMST+(INODE-1)*DELMST)/3600.D0,24.D0)
C
C          MAKE THE OBS REQMT MEAN ANOMALIES RELATIVE TO THE ORBIT
C          EVENT'S MEAN ANOMALY.  NEEDED ONLY WHEN MAX DETAIL IS GIVEN.
            IF(LEVDETFILE.EQ.4)
     *          CALL QUIKVIS5V(REQMTMA(1,1,INODE),EVENTMA(INODE),RELMA)
C
C          OUTPUT THE INFO FOR THIS TARGET, TIME, AND RAAN COMBINATION
C          WHEN LEVDETFILE
            IF(LEVDETFILE.EQ.3) THEN
              KTEMP = 1
              CH1 = '/'
            ELSE   ! LEVDETFILE=4
              KTEMP = MAXREQMT+1
              CH1 = ' '
              END IF
            WRITE(LUDETAIL,6901)
     *        ITARG,
     *        ID,
     *        PAKTIM50(T50),
     *        RAAN*DEGRAD,
     *        VISTIMES(INODE)/60.D0,
     *        XMST,
     *        EVENTMA(INODE)*DEGRAD,
     *        KTEMP,
     *        NLAP, (OVERLAP(1,J)*DEGRAD,OVERLAP(2,J)*DEGRAD,J=1,NLAP),
     *        CH1
            IF(LEVDETFILE.EQ.4)
     *         WRITE(LUDETAIL,6902)  ! MAX DETAIL
     *        (RELMA(1,I)*DEGRAD,RELMA(2,I)*DEGRAD,I=1,MAXREQMT)
C
            END IF    ! ENDS THE 'IF(LEVDETFILE.EQ.(3 OR 4))' BLOCK
C
          END DO   ! ENDS THE 'DO INODE LOOP'
C
C
C      SECOND(WHEN LEVDETFILE CALLS FOR THE DATA) FOR INDIVIDUAL
C      OBSERVATION REQUIREMENTS, DETERMINE THE COMPOSITE AVAILABILITY
C      OVER ALL NODES PROCESSED AT THE CURRENT TIME.
C
        IF(LEVDETFILE.GT.1) THEN
          CALL MTXSETR8(OVLAPREQ,0.D0,2*MAXOLAPREQ,MAXREQMT)
          CALL MTXSETI4(NOLAPREQ,0,MAXREQMT,1)
C
          DO IREQMT=1,MAXREQMT
            DO INODE=1,NUMNODES
              XMA1 = REQMTMA(1,IREQMT,INODE)
              XMA2 = REQMTMA(2,IREQMT,INODE)
              ALWAYS = XMA1.EQ.0.D0 .AND. XMA2.EQ.TWOPI
              IF(.NOT.ALWAYS) THEN
                XMA1 = EQVANG(XMA1-EVENTMA(INODE))
                XMA2 = EQVANG(XMA2-EVENTMA(INODE))
                END IF
              REQMA(1,INODE) = XMA1
              REQMA(2,INODE) = XMA2
              END DO  ! ENDS THE 'DO INODE' LOOP
            CALL ANGLAP(REQMA,NUMNODES,OVLAPREQ(1,1,IREQMT),
     *                    MAXOLAPREQ,NOLAPREQ(IREQMT),LUERR,IERR)
C          ERROR SHOULD NEVER OCCUR.  IF ERROR, STOP TO FORCE A LOOK.
            IF(IERR.NE.0) STOP 'QUIKVIS5A2C. ERROR STOP 3. SEE CODE.'
            END DO    ! ENDS THE 'DO IREQMT' LOOP
C
          END IF    ! ENDS THE 'IF(LEVDETDILE.GT.1)' BLOCK
C
C      WRITE INFO ON THE COMPOSITE AVAILABILITY FOR ALL NODES WITH 
C      THIS TARGET AND TIME COMBINATION.
C
          CALL QUIKVIS5A2C3(ITARG,ID,T50,SEGCIRC,NOLAPREQ,OVLAPREQ)
C
C      IF THIS IS A MAX OR ALMOST MAX DETAIL DATA FILE, WRITE A
C      SEPARATOR RECORD SO ONE READING A LISTING OF THE FILE CAN MORE
C      EASILY IDENTIFY THE END OF ONE TIME'S(T50) DATA RECORDS.  TIME
C      AND TARGET HAVE BEEN CONSTANT BUT NODE HAS BEEN CHANGING FOR EACH
C      RECORD, WITH THE LAST RECORD BEING THE COMPOSITE AVAILABILITY FOR
C      ALL NODES.
C
          IF(LEVDETFILE.EQ.3 .OR. LEVDETFILE.EQ.4) WRITE(LUDETAIL,6903)
C
C
C
 6000   CONTINUE   ! END IDETAIL LOOP
C
        END DO     ! END ITIME LOOP
C
 9999 CONTINUE
      RETURN
C
C***********************************************************************
C
C
C**** INITIALIZATION CALL. PUT GLOBAL PARAMETER VALUES INTO THIS
C     ROUTINE'S LOCAL VARIABLES.
C
      ENTRY QVINIT5A2C
C
      CALL QUIKVIS999(-1,R8DATA,I4DATA,L4DATA)
      RETURN
C
C***********************************************************************
C
C
 2010 FORMAT(/,
     *  '1DETAIL TARGET AVAILABILITY INFO',T90,'GENERATED ',A/,
     *  ' *******************************'///,
     *  ' TARGET ID = ',I5,'    TARGET NAME= ',A//,
     *  ' OBSERVATION REQUIREMENTS:'//,
     *  T7,A/,
     *  T7,'EARTH LIMB AVOIDANCE ANGLE(DEG)= ',F8.2/,
     *  T7,'VELOCITY VECTOR AVOIDANCE ANGLE= ',F8.2/,
     *  T7,'MAX OK SEPARATION FROM ZENITH=   ',F8.2)
 2110 FORMAT(//,
     *  ' Y/M/D H:M:S = ',A,'  DAYS SINCE FIRST DATE= ',F7.3/,
     *  ' SUN(M50):    RA,DEC(DEG)=',2F8.2,'  DISTANCE(AU)=',G17.9)
 2111 FORMAT(
     *  ' TARGET(M50): RA,DEC(M50)=',2F8.2,'  DISTANCE(AU)=',G17.9)
 2113 FORMAT(//,
     *  ' THE FOLLOWING TABLE GIVES THE MEAN ANOMALIES AT WHICH ',
     *         'INDIVIDUAL OBSERVATION REQUIREMENTS BEGIN AND ',
     *         'CEASE TO BE SATISFIED.'//,
     *  ' MEAN ANOMALIES ARE RELATIVE TO ORBIT EVENT:  'A//,
     *  ' BEGIN,CEASE= 0,0 MEANS THE REQUIREMENT IS NEVER SATISFIED.',
     *         '   BEGIN,CEASE= 0,360 MEANS THE REQUIREMENT ',
     *         'IS ALWAYS SATISFIED.'/,
     *  ' COLUMN HEADINGS: RAAN IS THE ORBIT RIGHT ASCENSION OF THE ',
     *       'ASCENDING NODE.  MST IS THE ASCENDING NODE''S MEAN ',
     *       'SOLAR TIME.'//,
     *  '       RAAN    RAAN    AVAIL       EVENT       ',
     *       'MA: OK HORIZON      MA: OK DAY/NIGHT ',
     *       '   MA: OK VEL VEC      MA: OK ZENITH'/,
     *  '      (DEG)     MST    (MIN)         MA        ',
     *      'BEGIN   CEASE       BEGIN   CEASE     ',
     *       '  BEGIN   CEASE       BEGIN   CEASE'/,
     *  '               (HR)                (DEG)       ',
     *      '(DEG)   (DEG)       (DEG)   (DEG)     ',
     *       '  (DEG)   (DEG)       (DEG)   (DEG)'/)
 2114 FORMAT(6X,F5.1,3X,F5.2,3X,F6.2,6X,F6.1,
     *        <MAXREQMT>(6X,F6.1,2X,F6.1))
 3099 FORMAT(//,
     *  ' THE FOLLOWING SHOWS THE MEAN ANOMALIES AT WHICH ',
     *    'INDIVIDUAL OBSERVATION REQUIREMENTS BEGIN AND CEASE TO BE'/,
     *  ' SATISFIED.  AN ''*'' INDICATES THE REQUIREMENT IS ',
     *  ' SATISFIED, A BLANK INDICATES IT IS VIOLATED.'//,
     *  ' MEAN ANOMALIES ARE RELATIVE TO ORBIT EVENT:  'A//)
 3100 FORMAT(//,
     *  ' RIGHT ASCN OF ASC NODE(DEG)= ',F5.1,
     *    '   NODE''S MEAN SOLAR TIME(HR)= ',F5.2,
     *    '   DURATION AVAILABLE(MINUTES)= ',F6.2)
 3101 FORMAT(1X,A,1X,A)
 3102 FORMAT(T12,'*',24('    *')/,' M-ANOM=',T12,'0',24I5)
 4100 FORMAT(1X,F5.<NDECIML>,1X,T8,A)
 4101 FORMAT(1X,A,T8,A,12A)
 4102 FORMAT(' DT=',T8,'0',12(7X,I3))
 4103 FORMAT(//,
     *  ' THE FOLLOWING SHOWS WHEN TARGET AVAILABILITY BEGINS AND ',
     *      'CEASES.  IN MINUTES AFTER EVENT:  ',A/)
 4104 FORMAT(///,
     *  ' THE FOLLOWING GIVES A ROUGH INDICATION OF GUARANTEED ',
     *      'AVAILABILITY FOR ALL RAAN''S PROCESSED.'/,
     *  ' THIS BAR WAS DERIVED BY OVERLAYING ALL OF THE BARS ',
     *      'ABOVE, NOT BY OVERLAYING THE ACTUAL TIMES.'//,
     *  ' BAR=',T8,A)
 4105 FORMAT(' THE FIRST RAAN = ',F6.2,' DEGREES,  THE FIRST RAAN''S ',
     *          'MEAN SOLAR TIME = ',F5.2//)
 6901 FORMAT(1X,I4,',',I5,',',F14.6,',',F8.3,',',F7.3,',',F8.3,',',
     *      F8.3,', ',I2,','/,
     *      T6,I2,',',<NLAP>(F7.2,',',F7.2,','),A)
 6902 FORMAT(T7,<MAXREQMT>('1,',F7.2,',',F7.2,','),'/')
 6903 FORMAT('  0/ ',65('*'))
 7201 FORMAT(//,
     *   ' QUIKVIS5A2C.  ERROR.  PERIOD IS TOO LONG FOR OUTPUT OPTION'/,
     *   '               OPTION CANCELLED. MAX PERIOD = 120 MINUTES.'//)
      END
